class SingleSimple {

  constructor (chart, params = {}) {
    this._chart = chart
    this._params = params
  }

  render (source) {
    const option = this.getOptions({ source, ...this._params })
    this._chart.setOption(option)
  }

  getOptions ({ source = [], color = [ '#4267E0', '#46BAFF', '#8795de', '#46BAFF', '#FF5050' ], serieName, title, subTitle }) {
    const legendData = source.map(v => v.name)
    return {
      color: color,
      title : {
        text: title || '未知',
        subtext: subTitle || '',
        x:'center'
      },
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      series: [
        {
          name: serieName,
          type: 'pie',
          center: ['50%', '50%'],
          radius : '40%',
          labelLine: {
            normal: {
              show: true
            }
          },
          data: source
        }
      ]
    }
  }
}

export default SingleSimple
